package com.yylany.service.impl;

import com.yylany.mapper.AgencyMapper;
import com.yylany.mapper.UserMapper;
import com.yylany.page.PageData;
import com.yylany.page.PageParams;
import com.yylany.pojo.Agency;
import com.yylany.pojo.User;
import com.yylany.service.AgencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * User  yyl
 * Description: house
 * Created by yaoyonglong on 2018/11/5 20:16
 */
@Service
public class AgencyServiceImpl implements AgencyService {
    @Value("${file.prefix}")
    private String imgPrefix;

    @Autowired
    private AgencyMapper agencyMapper;

    @Autowired
    private UserMapper userMapper;


    @Override
    public List<Agency> getAllAgency() {
        return agencyMapper.selectAll();
    }

    private void setImg(List<User> list) {


        list.forEach(i -> {
            i.setAvatar(imgPrefix + i.getAvatar());
        });

    }

    public PageData<User> getAllAgent(PageParams pageParams) {

        List<User> user = userMapper.selectAll();
        setImg(user);
        Long count = Long.parseLong(user.size() + "");
        return PageData.buildPage(user, count, pageParams.getPageSize(), pageParams.getPageNum());
    }

    @Override
    public Agency getAgentDeail(Long userId) {

        return agencyMapper.selectByPrimaryKey(Integer.parseInt(userId + ""));
    }
}
